/**
 * 全项目本地存储主键，防止魔法定义
 */
export const enum LocalStorageKey {
  /** 存储是否登录，登录时值为1 */
  LOGIN = 'CHUNMI_LOGIN',
}

/**
 * 存储键值对
 * @param key 键
 * @param value 值
 */
const setItem = (key: LocalStorageKey, value: any) => {
  localStorage.setItem(key.toString(), String(value))
}

/**
 * 获取键对应的值
 * @param key 键
 */
const getItem = (key: LocalStorageKey): string | null => {
  return localStorage.getItem(key.toString())
}

/**
 * 删除对应的键值对
 * @param key 键
 */
const removeItem = (key: LocalStorageKey) => {
  localStorage.removeItem(key.toString())
}

/**
 * 本地存储服务
 */

export const localStorageApi = {
  setItem,
  getItem,
  removeItem,
}
